<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <!-- 自定义按钮请使用插槽，甚至公共搜索也可以使用具名插槽渲染，参见文档 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'columnDisplay']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: t('shopWithdraw.quick Search Fields') })"
        ></TableHeader>

        <!-- 表格 -->
        <!-- 表格列有多种自定义渲染方式，比如自定义组件、具名插槽等，参见文档 -->
        <!-- 要使用 el-table 组件原有的属性，直接加在 Table 标签上即可 -->
        <Table ref="tableRef"></Table>

        <!-- 表单 -->
        <PopupForm />


        <!--审核-->
        <el-dialog
            v-model="check_show"
            title="提现审核"
            width="500"
        >


            <template #header>
                <div class="title" style="border-bottom:1px solid var(--ba-bg-color);padding-bottom: 16px;" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                    提现审核
                </div>
            </template>
            <!--            提示：<br>-->
            <!--            &nbsp;&nbsp;&nbsp;&nbsp;1、默认将联系方式字段;<br>-->
            <!--            &nbsp;&nbsp;&nbsp;&nbsp;2、机具号为唯一标识，如果新导入的绑定数据已在订单中，将导入失败！<br>-->
            <!--            <br><br>-->
            <el-descriptions
                style="margin-top: -20px"
                direction="vertical"
                :column="3"
                border
            >
                <el-descriptions-item label="提现金额">{{check_data.money}}</el-descriptions-item>
                <el-descriptions-item label="手续费">{{check_data.server_money}}</el-descriptions-item>
                <el-descriptions-item label="到账金额">{{check_data.arrival_money}}</el-descriptions-item>

            </el-descriptions>
            <p style="margin-top: 20px"></p>
            <FormItem label="审核结果" type="radio"  v-model="check_data.status_"  :data="{ content: {  '1': '通过', '2': '驳回' } }" />
            <FormItem label="驳回理由" type="textarea" v-if="check_data.status_ == 2"  v-model="check_data.reason_" placeholder="请输入驳回理由" />

            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="check_show = false">取消</el-button>
                    <el-button type="primary" @click="sub_check">
                        确认
                    </el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog
            v-model="info_show"
            title="审核详情"
            width="550"
        >

            <template #header>
                <div class="title" style="border-bottom:1px solid var(--ba-bg-color);padding-bottom: 16px;" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                    审核详情
                </div>
            </template>
            <!--            提示：<br>-->
            <!--            &nbsp;&nbsp;&nbsp;&nbsp;1、默认将联系方式字段;<br>-->
            <!--            &nbsp;&nbsp;&nbsp;&nbsp;2、机具号为唯一标识，如果新导入的绑定数据已在订单中，将导入失败！<br>-->
            <!--            <br><br>-->



            <el-descriptions
                style="margin-top: -20px"
                direction="vertical"
                :column="2"
                border
            >
                <el-descriptions-item label="用户昵称">{{check_data?.user?.nickname}}（ID:{{check_data.user_id}}）</el-descriptions-item>
                <el-descriptions-item label="商家名称">{{check_data?.shop?.name}}（ID:{{check_data.shop_id}}）</el-descriptions-item>
                <el-descriptions-item label="提现金额">{{check_data.money}}</el-descriptions-item>
                <el-descriptions-item label="手续费">{{check_data.server_money}}</el-descriptions-item>
                <el-descriptions-item label="到账金额">{{check_data.arrival_money}}</el-descriptions-item>
                <el-descriptions-item label="审核时间">{{check_data.check_time_text}}</el-descriptions-item>
                <el-descriptions-item label="审核人">{{check_data.admin_name}}</el-descriptions-item>
                <el-descriptions-item label="审核结果">
                    <span v-if="check_data.status == 9">驳回</span>
                    <span v-else>通过</span>
                </el-descriptions-item>
                <el-descriptions-item label="驳回理由">
                    <span v-if="check_data.reject_reason">{{check_data.reject_reason}}</span>
                    <span v-else>-</span>
                </el-descriptions-item>
            </el-descriptions>


        </el-dialog>

    </div>
</template>

<script setup lang="ts">
import { onMounted, provide, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import { baTableApi } from '/@/api/common'
import { defaultOptButtons } from '/@/components/table'
import TableHeader from '/@/components/table/header/index.vue'
import Table from '/@/components/table/index.vue'
import baTableClass from '/@/utils/baTable'
import {auth} from "/@/utils/common";
import createAxios from "/@/utils/axios";
import {ElMessage} from "element-plus";
import FormItem from "/@/components/formItem/index.vue";
import {useAdminInfo} from "/@/stores/adminInfo";

defineOptions({
    name: 'shopWithdraw',
})

const { t } = useI18n()
const tableRef = ref()
const optButtons: OptButton[] = defaultOptButtons(['edit', 'delete'])

const auth_check = auth({ name: '/admin/shopWithdraw', subNodeName: '/admin/shopWithdraw/check' })
optButtons.push(
    {
        render: 'tipButton',
        name: 'check',
        title: '审核',
        text: '',
        type: 'success',
        icon: 'fa fa-check-square-o',
        class: 'table-row-info',
        click(row, field) {
            check_data.value = row;
            check_show.value = true;
        },
        display: (row, field) => {
            if (auth_check && row.status == 1)
            {
                return true
            }else {
                return false;
            }
        },
    },
    {
        render: 'tipButton',
        name: 'check',
        title: '审核详情',
        text: '',
        type: 'primary',
        icon: 'fa fa-info-circle',
        class: 'table-row-info',
        click(row, field) {
            check_data.value = row;
            info_show.value = true;
        },
        display: (row, field) => {
            if (auth_check && row.status != 1)
            {
                return true
            }else {
                return false;
            }
        },
    },
)
/**
 * baTable 内包含了表格的所有数据且数据具备响应性，然后通过 provide 注入给了后代组件
 */
const baTable = new baTableClass(
    new baTableApi('/admin/shopWithdraw/'),
    {
        pk: 'id',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('shopWithdraw.id'), prop: 'id', align: 'center', width: 70, operator: 'RANGE', sortable: 'custom' },
            { label: t('shopWithdraw.user_id'),width:100, prop: 'user_id', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE' },
            { label: t('shopWithdraw.user__nickname'),width:150, prop: 'user.nickname', align: 'center', operatorPlaceholder: t('Fuzzy query'),operator: 'LIKE' },
            // { label: t('shopWithdraw.user__mobile'), prop: 'user.mobile', align: 'center', operatorPlaceholder: t('Fuzzy query'), render: 'tags', operator: 'LIKE' },
            { label: t('shopWithdraw.shop__name'),show:useAdminInfo().admin_type == 1 ? true : false,width:150, prop: 'shop.name', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE' },
            { label: t('shopWithdraw.order_no'),width:210, prop: 'order_no', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('shopWithdraw.money'),width:150, prop: 'money', align: 'center', operator: 'RANGE', sortable: true },
            { label: t('shopWithdraw.server_money'),width:150, prop: 'server_money', align: 'center', operator: 'RANGE', sortable: true },
            { label: t('shopWithdraw.arrival_money'),width:150, prop: 'arrival_money', align: 'center', operator: 'RANGE', sortable: true },
            { label: t('shopWithdraw.status'),width:130, prop: 'status', align: 'center', render: 'tag', operator: 'eq', sortable: true, replaceValue: { '1': t('shopWithdraw.status 1'), '2': t('shopWithdraw.status 2'), '9': t('shopWithdraw.status 9') } },
            { label: t('shopWithdraw.wx_status'),width:150, prop: 'wx_status', align: 'center', render: 'tag', operator: 'eq', sortable: true, replaceValue: { '0': t('shopWithdraw.null0'),'ACCEPTED': t('shopWithdraw.ACCEPTED'),'PROCESSING': t('shopWithdraw.PROCESSING'),'WAIT_USER_CONFIRM': t('shopWithdraw.WAIT_USER_CONFIRM'),'TRANSFERING': t('shopWithdraw.TRANSFERING'),'SUCCESS': t('shopWithdraw.SUCCESS'), 'FAIL': t('shopWithdraw.FAIL') } },
            { label: t('shopWithdraw.admin_name'), prop: 'admin_name', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('shopWithdraw.check_time'), prop: 'check_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('shopWithdraw.reject_reason'), prop: 'reject_reason', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            // { label: t('shopWithdraw.accounting_time'), prop: 'accounting_time', align: 'center', operator: 'RANGE', sortable: false },
            // { label: t('shopWithdraw.params'), prop: 'params', align: 'center', operatorPlaceholder: t('Fuzzy query'), operator: 'LIKE', sortable: false },
            { label: t('shopWithdraw.create_time'), prop: 'create_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            // { label: t('shopWithdraw.update_time'), prop: 'update_time', align: 'center', render: 'datetime', operator: 'RANGE', sortable: 'custom', width: 160, timeFormat: 'yyyy-mm-dd hh:MM:ss' },
            { label: t('Operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false, fixed: 'right'},
        ],
        dblClickNotEditColumn: false,
    },
    {
        defaultItems: { money: 0, server_money: 0, arrival_money: 0, status: '1', check_time: 0, accounting_time: 0 },
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})


/**
 * 审核
 */
const check_data = ref({});
const check_show = ref(false);
const info_show = ref(false);
const sub_check = () => {
    createAxios({
        url: '/admin/shopWithdraw/check',
        method: 'post',
        data: check_data.value
    },{
        loading:true
    },{
        text: '提交中...'
    })
        .then((res) => {
            if (res.code == 1){
                ElMessage({
                    message: res.msg,
                    type: 'success',
                })
                baTable.onTableHeaderAction('refresh', {})
                check_show.value = false;
                check_data.value = '';
            }else {
                ElMessage({
                    message: res.msg,
                    type: 'error',
                })
            }

        })
        .catch((resx) => {
        })
}
</script>

<style scoped lang="scss"></style>
